package com.sxt.core.net.impl;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import com.sxt.core.anno.AutoBuilder;
import com.sxt.core.net.NetClientService;

@AutoBuilder
public class IOSocketNetClientService implements NetClientService {

	private Socket socket = null ;
	
	@Override
	public InputStream getInputStream() {
		InputStream inputStream = null ;
		try {
			inputStream = socket.getInputStream();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return inputStream;
	}

	@Override
	public OutputStream getOutputStream() {
		OutputStream outputStream = null ;
		try {
			outputStream = socket.getOutputStream();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return outputStream;
	}

	@Override
	public  void createConnection(String address) {
		String[] serverAddress = address.split(":");
		try {
			socket = new Socket(serverAddress[0], Integer.valueOf(serverAddress[1]));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
